package cn.wolfcode.crm.domain;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.Getter;
import lombok.Setter;

@Setter @Getter
public class CustomerTraceHistory {
	private Long id;
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	private Date traceTime; // 跟进时间
	private String traceDetails;// 跟进内容
	private Long traceTypeId; // 跟进方式
	private Integer traceResult;// 跟进结果 1差 2中 3优
	private String remark; // 备注
	
	private Long inputUserId;

	private Employee inputUser;
	private Customer customer;
	private Date inputTime; // 录入时间
	
	public String getJson() throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		Map<String, Object> map = new HashMap<>();
		map.put("id", id);
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String trace_time = sf.format(traceTime);
		map.put("traceTime", trace_time);
		map.put("traceDetails", traceDetails);
		map.put("traceTypeId", traceTypeId);
		map.put("traceResult", traceResult);
		map.put("remark", remark);
		map.put("customerId", customer.getId());
		map.put("customerName", customer.getName());
		return mapper.writeValueAsString(map);
	}
	
	public String getTraceTypeName() {
		String msg = "";
		switch (traceTypeId.intValue()) {
		case 9:
			msg = "微信";
			break;
		case 10:
			msg = "营销QQ";
			break;
		case 11:
			msg = "来电查询";
			break;
		case 12:
			msg = "去电跟踪";
			break;
		case 13:
			msg = "短信";
			break;
		default:
			break;
		}
		return msg;
	}
	
	public String getTraceResultName() {
		//跟进结果 1差 2中 3优
		String msg = "";
		switch (traceResult.intValue()) {
		case 1:
			msg = "差";
			break;
		case 2:
			msg = "中";
			break;
		case 3:
			msg = "优";
			break;
		default:
			break;
		}
		return msg;
	}

}
